package com.example.mylibrary;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;


@SuppressLint("AppCompatCustomView")
public class MyTextView extends TextView {


    public MyTextView(Context context) {
        super(context);
    }

    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setFont(context, attrs);
    }

    public MyTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setFont(context, attrs);
    }

    private void setFont(Context context, AttributeSet attrs) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MyTextView);
        String a = typedArray.getString(R.styleable.MyTextView_fontsFamily);
        Typeface myFont;
        if (a != null) {
            switch (a) {
                case "0":
                    a = "alkatip";
                    break;
                case "1":
                    a = "UKIJEkran";
                    break;
                case "2":
                    a = "UKIJTor";
                    break;
            }
            myFont = Typeface.createFromAsset(context.getAssets(), a + ".ttf");
        } else {
            myFont = Typeface.createFromAsset(context.getAssets(), "UKIJEkran.ttf");
        }
        setTypeface(myFont);
    }
}
